import {
  getTechnologyTypeList,
  getYesOrNotList,
} from "@/api/process/mesTechnology";
import {
  getLineCodeListNew,
} from "@/api/process/mesProcess";
import { deleteFile } from "@/api/common";
import app from "@/main";
import url from "@/axios/url";
const { messerviceUrl } = url();

// 列表头按钮配置
export const operateList = [
  {
    name: $i18n.t("common.add"),
    type: "primary",
    icon: "el-icon-circle-plus-outline",
    handleName: "add", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    icon: "el-icon-delete",
    isMultiple: true, //至少选择一条
    disabled: (data) => {
      return !data.length > 0;
    },
    handleName: "deleteBatch", //点击时返回的标识
  },
  {
    name: $i18n.t("mesTechnology.publish"),
    type: "success",
    icon: "el-icon-s-promotion",
    isMultiple: true, //至少选择一条
    //是否可点击；
    disabled: (data) => {
      return data.length != 1;
    },
    handleName: "publish", //点击时返回的标识
  },
  {
    name: $i18n.t("mesTechnology.deactivate"),
    type: "warning",
    icon: "el-icon-error",
    handleName: "deactivate", //点击时返回的标识

    isMultiple: true, //至少选择一条
    //是否可点击；
    disabled: (data) => {
      return data.length != 1;
    },
  },

  {
    name: $i18n.t("mesTechnology.upgrade"),
    type: "primary",
    icon: "el-icon-top",
    isMultiple: true, //至少选择一条
    //是否可点击；
    disabled: (data) => {
      return data.length != 1;
    },
    handleName: "upgrade", //点击时返回的标识
  },
  {
    name: $i18n.t("mesTechnology.technologyCopy"),
    type: "primary",
    icon: "el-icon-top",
    isMultiple: true, //至少选择一条
    handleName: "copy", //点击时返回的标识
  },
];
// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("common.edit"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "edit", //点击时返回的标识
  },
  {
    name: $i18n.t("common.details"),
    type: "info",
    class: "row-btn-info",
    handleName: "detail", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    class: "row-btn-danger",
    handleName: "delete", //点击时返回的标识
  },
];
// 搜索条件配置
export const searchConfig = {
  data() {
    const _this = this;
    return {
      searchConfig: {
        inline: true,
        formDesc: {
          technologyCode: {
            type: "input",
            label: $i18n.t("mesTechnology.technologyCode"),
          },
          technologyName: {
            type: "input",
            label: $i18n.t("mesTechnology.technologyName"),
          },
          seriesCode: {
            type: "input",
            label: $i18n.t("mesTechnology.seriesCode"),
          },
          prodCode: {
            type: "input",
            label: $i18n.t("mesTechnology.prodCode"),
          },
          isDefaultTechnology: {
            type: "select",
            label: $i18n.t("mesTechnology.isDefaultTechnology"),
            prop: {
              value: "value",
              text: "description",
            },
            options: async (data) => {
              const list = await getYesOrNotList();
              return list.data.result;
            },
          },
          technologyType: {
            label: $i18n.t("mesTechnology.technologyType"),
            type: "select",
            prop: {
              value: "value",
              text: "description",
            },
            options: async (data) => {
              const list = await getTechnologyTypeList();
              return list.data.result;
            },
          },
          prodName: {
            type: "input",
            label: $i18n.t("mesTechnology.prodName"),
          },
          workshopCode: {
            type: "select",
            label: $i18n.t("mesTechnology.workshopCode"),
            prop: {
              value: "modelingCode",
              text: "modelingName",
            },
            options: async (data) => {
              const params = {
                modelingCode: this.$store.getters.factoryCode,
                level: 4,
                modelingType: "0",
              };
              const list = await getLineCodeListNew(params);
              console.log(999, list);
              // this.workshopList = list.data.result;
              return list.data.result;
            },
          },
        },
      }
    }
  }
};
// 新增/删除表单配置
export const formDescDialog = {
  span: 24,
  disabled: false,
  isShowSubmitBtn: true,
  formDesc: {
    technologyCode: {
      type: "input",
      label: $i18n.t("mesTechnology.technologyCode"),
      layout: 12,
      disabled: (d) => !!d.id,
      required: false,
    },
    technologyName: {
      type: "input",
      label: $i18n.t("mesTechnology.technologyName"),
      layout: 12,
      required: false,
    },
    technologyType: {
      type: "select",
      label: $i18n.t("mesTechnology.technologyType3"),
      layout: 12,
      required: false,
      prop: {
        value: "value",
        text: "description",
      },
      options: async (data) => {
        const list = await getTechnologyTypeList();
        return list.data.result;
      },
    },
    prodCode: {
      type: "input",
      label: $i18n.t("mesTechnology.prodCode2"),
      layout: 12,
      required: false,
    },
    prodName: {
      type: "input",
      label: $i18n.t("mesTechnology.prodName2"),
      layout: 12,
      required: false,
    },
    standardTime: {
      type: "number",
      label: $i18n.t('mesTechnology.standardTime'),
      layout: 12,
      required: false,
    },
    assistTime: {
      type: "number",
      label: $i18n.t('mesTechnology.assistTime'),
      layout: 12,
      required: false,
    },
    technologyFile: {
      type: "upload-file",
      label: $i18n.t("mesTechnology.technologyFile"),
      layout: 12,
      required: false,
      attrs: {
        // limit: 2,
        action: `${messerviceUrl}file`,
        data: {
          bucket: "messervice",
        },
        beforeRemove: (data, list) => {
          const bucket = "messervice";
          let filename = data.name;

          return new Promise((resolve, reject) => {
            deleteFile(`${messerviceUrl}file`, { bucket, filename })
              .then((res) => {
                resolve(res.data);
              })
              .catch((error) => {
                reject(error);
              });
          });
        },
        // autoUpload: false,
        responseFn(response, file) {
          if (response.code === 0) {
            return {
              name: file.name,
              url: response.result.path, // 文件id
              size: file.size,
              ...response.result,
            };
          }
        },
      },
    },
    versionNumber: {
      type: "input",
      label: $i18n.t("mesTechnology.versionNumber"),
      layout: 12,
      disabled: (d) => !!d.id,
      required: false,
    },
    Remark: {
      type: "textarea",
      label: $i18n.t("mesTechnology.Remark"),
      layout: 12,
      required: false,
    },
  },
};
